package sun.circleprogerss;

import android.util.Log;

import net.tsz.afinal.annotation.sqlite.Id;
import net.tsz.afinal.annotation.sqlite.Table;

import java.io.Serializable;
import java.util.Comparator;
import java.util.List;

import sun.curriculumschedule.util.DatabaseUtil;

/**
 * Created by 松子 on 2015/11/19.
 */
@Table(name = "system_lesson")
public class SystemLesson implements Serializable,Cloneable {
    @Id(column="lesson_id")
    private int lesson_id;
    private String lesson_name;
    private int subDomain_id;
    private String jsonData;
    private int teacher_id;
    private int masterDomain_id;
    private int school_id;
    private String teacher_name;
    private String info;
    private String date;
    private int type;
    private int level;


    public SystemLesson() {
    }

    public SystemLesson(int teacherId, String LessonName, int lessonType){
        this.teacher_id = teacherId;
        this.lesson_name = LessonName;
        this.type = lessonType;
    }
    /**
     * 克隆对象
     * @return
     */
    public Object clone(){
        Object o = null;
        try{
            o = (CustomLesson) super.clone();
        }
        catch (CloneNotSupportedException e){
            System.out.println(e.toString());
            Log.i("clone exception", e.toString());
        }
        return o;
    }

    public static List<CustomLesson> dataBaseFindLessons(String lessonName, int type){
        return DatabaseUtil.getDb().findAllByWhere(
                CustomLesson.class,
                "lesson_name=" +  "'" +
                        lessonName + "' and "+"type="
                        +"'"+type+"'");
    }

    public int getLesson_id() {
        return lesson_id;
    }

    public void setLesson_id(int lesson_id) {
        this.lesson_id = lesson_id;
    }

    public String getLesson_name() {
        return lesson_name;
    }

    public void setLesson_name(String lesson_name) {
        this.lesson_name = lesson_name;
    }

    public int getSubDomain_id() {
        return subDomain_id;
    }

    public void setSubDomain_id(int subDomain_id) {
        this.subDomain_id = subDomain_id;
    }

    public String getJsonData() {
        return jsonData;
    }

    public void setJsonData(String jsonData) {
        this.jsonData = jsonData;
    }

    public int getTeacher_id() {
        return teacher_id;
    }

    public void setTeacher_id(int teacher_id) {
        this.teacher_id = teacher_id;
    }

    public int getMasterDomain_id() {
        return masterDomain_id;
    }

    public void setMasterDomain_id(int masterDomain_id) {
        this.masterDomain_id = masterDomain_id;
    }

    public int getSchool_id() {
        return school_id;
    }

    public void setSchool_id(int school_id) {
        this.school_id = school_id;
    }

    public String getTeacher_name() {
        return teacher_name;
    }

    public void setTeacher_name(String teacher_name) {
        this.teacher_name = teacher_name;
    }

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }
/*    public String getThumbnail(){return thumbnail;}

    public void setThumbnail(String thumbnail){this.thumbnail=thumbnail;}*/

//    public static boolean isJsonAvailable(String jsonData){
////        String jsonData = customLessonList.get(position).getJsonData();
////         lessonJsonData = null;
//        boolean isAvailable = false;
//        if (jsonData != null) {
//            LessonJsonData lessonJsonData = JsonLesson.StringToBaseExercise(jsonData);
//
//            if (lessonJsonData.getExercises() != null && lessonJsonData.getExercises().size() > 0) {
//                ArrayList<LessonJsonDataExercise> preLessonJsonDataExercise = (ArrayList<LessonJsonDataExercise>) lessonJsonData.getExercises();
//                loop:
//                for (LessonJsonDataExercise lessonJsonDataExercise : preLessonJsonDataExercise) {
//                    ArrayList<LessonJsonDataUnit> preUnit = lessonJsonDataExercise.getUnits();
//                    String exerciseType = lessonJsonDataExercise.getExerciseType();
//
//                    for (LessonJsonDataUnit lessonJsonDataUnit : preUnit) {
//                        isAvailable = LessonJsonDataUnit.isUnitAvailable(lessonJsonDataUnit, exerciseType);
//                        if (!isAvailable) {
//                            break loop;
//                        }
//                    }//end for
//
//                    // if (!isAvailable)break;
//                }//end for
//            }//end if
//        }//end if
//        return isAvailable;
//    }
    @Override
    public String toString() {
        return "CustomLesson{" +
                "lesson_id=" + lesson_id +
                ", lesson_name='" + lesson_name + '\'' +
                ", subDomain_id=" + subDomain_id +
                ", jsonData='" + jsonData + '\'' +
                ", teacher_id=" + teacher_id +
                ", masterDomain_id=" + masterDomain_id +
                ", school_id=" + school_id +
                ", teacher_name='" + teacher_name + '\'' +
                ", info='" + info + '\'' +
                ", date='" + date + '\'' +
                ", type=" + type +
                ", level=" + level +
              /*  ", thumbnail='"+thumbnail+'\''+*/
                '}';
    }

    public static class SortCustomList implements Comparator {
        public int compare(Object o1, Object o2) {
            SystemLesson s1 = (SystemLesson) o1;
            SystemLesson s2 = (SystemLesson) o2;
            if(s1.getLesson_name().compareTo(s2.getLesson_name()) < 0)
                return 1;
            else if (s1.getLesson_name().compareTo(s2.getLesson_name()) > 0) {
                return -1;
            } else {
                if (s1.getType() < s2.getType()) {
                    return -1;
                } else if (s1.getType() > s2.getType()) {
                    return 1;
                }
            }
            return 0;
        }
    }
}
